package com.ruoyi.web.controller.vqms;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.led.CfLinXinLed;
import com.ruoyi.system.domain.led.CfLinXinLedArea;
import com.ruoyi.system.domain.led.CfLinXinLedProgram;
import com.ruoyi.vqms.domain.VQMSDriver;
import com.ruoyi.vqms.domain.VQMSLed;
import com.ruoyi.vqms.service.IVQMSLedService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * LED大屏 控制器
 */
@RestController
@RequestMapping("/vqms/led")
public class VQMSLedController extends BaseController {
    @Autowired
    private IVQMSLedService ledService;

    /**
     * 查询LED大屏列表
     */
    @PreAuthorize("@ss.hasPermi('vqms:led:list')")
    @RequestMapping("/list")
    public TableDataInfo list(VQMSLed vqmsLed){
        startPage();
        List<VQMSLed> list=ledService.selectList(vqmsLed);
        return getDataTable(list);
    }

    /**
     * 新增LED大屏
     */
    @Log(title = "新增LED大屏", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('vqms:led:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody VQMSLed vqmsLed){
        vqmsLed.setCreateBy(SecurityUtils.getUsername());
        ledService.add(vqmsLed);
        return AjaxResult.success();
    }

    /**
     * 查询LED大屏
     */
    @PreAuthorize("@ss.hasPermi('vqms:led:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(ledService.getById(id));
    }

    /**
     * 修改LED大屏
     */
    @Log(title = "修改LED大屏", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('vqms:driver:update')")
    @PutMapping(value = "/update")
    public AjaxResult update(@RequestBody VQMSLed vqmsLed)
    {
        vqmsLed.setUpdateBy(SecurityUtils.getUsername());
        ledService.update(vqmsLed);
        return AjaxResult.success();
    }

    @RequestMapping("/setTcpData")
    @ApiOperation(value = "根据Query条件查询数据")
    public AjaxResult setTcpData(String serialNumber, Integer screenWidth, Integer screenHigh, Integer x, Integer y, Integer width, Integer high, Integer fontRowSpacing, String contents) throws Exception  {
        // contents：要发送到LED的数据（排队信息数据）
        //【文本列表】
        ArrayList<CfLinXinLedArea> cfLinXinLedAreaArrayList = new ArrayList<>();
        //文本1
        cfLinXinLedAreaArrayList.add(new CfLinXinLedArea(1, x, y, width, high, 1, 16, 16, 0, 1, 4, 3, x, y, width, high, 1, fontRowSpacing, 0, contents));
        //【节目】
        //节目1
        CfLinXinLedProgram cfLinXinLedProgram = new CfLinXinLedProgram(0, 0, 1, cfLinXinLedAreaArrayList);
        //【第一个主板内容】
        ArrayList<CfLinXinLedProgram> cfLinXinLedProgramArrayList = new ArrayList<>();
        cfLinXinLedProgramArrayList.add(cfLinXinLedProgram);
        CfLinXinLed cfLinXinLed = new CfLinXinLed(screenWidth, screenHigh, 1, 5, 2, cfLinXinLedProgramArrayList);
//        ledService.sendTcpData(serialNumber, cfLinXinLed);
        return AjaxResult.success("200",cfLinXinLed);
    }

    /**
     * 删除LED大屏
     */
    @Log(title = "删除LED大屏", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('vqms:driver:delete')")
    @DeleteMapping(value = "/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        return AjaxResult.success(ledService.delete(ids));
    }


}
